part of '../repository.dart';

class _LexicalItemDtoFactory {
  const _LexicalItemDtoFactory._internal();

  static const _instance = _LexicalItemDtoFactory._internal();

  factory _LexicalItemDtoFactory() {
    return _instance;
  }

  _LexicalItemDto fromJson(Map<String, dynamic> json) {
    final String type = json[_kLexicalItemTypeKey];

    switch (type) {
      case _kUnspecifiedWordTypeValue:
        return _UnspecifiedWordDto.fromJson(json);
      case _kAdjectiveTypeValue:
        return _AdjectiveDto.fromJson(json);
      case _kAdverbTypeValue:
        return _AdverbDto.fromJson(json);
      case _kConjunctionTypeValue:
        return _ConjunctionDto.fromJson(json);
      case _kNounTypeValue:
        return _NounDto.fromJson(json);
      case _kNumeralTypeValue:
        return _NumeralDto.fromJson(json);
      case _kPrepositionTypeValue:
        return _PrepositionDto.fromJson(json);
      case _kPronounTypeValue:
        return _PronounDto.fromJson(json);
      case _kVerbTypeValue:
        return _VerbDto.fromJson(json);
      case _kPhrasalVerbTypeValue:
        return _PhrasalVerbDto.fromJson(json);
      default:
        throw UnimplementedError();
    }
  }

  _LexicalItemDto fromEntity(LexicalItem lexicalItem) {
    switch (lexicalItem) {
      case UnspecifiedWord():
        return _UnspecifiedWordDto.fromEntity(lexicalItem);
      case Adjective():
        return _AdjectiveDto.fromEntity(lexicalItem);
      case Adverb():
        return _AdverbDto.fromEntity(lexicalItem);
      case Conjunction():
        return _ConjunctionDto.fromEntity(lexicalItem);
      case Noun():
        return _NounDto.fromEntity(lexicalItem);
      case Numeral():
        return _NumeralDto.fromEntity(lexicalItem);
      case Preposition():
        return _PrepositionDto.fromEntity(lexicalItem);
      case Pronoun():
        return _PronounDto.fromEntity(lexicalItem);
      case Verb():
        return _VerbDto.fromEntity(lexicalItem);
      case PhrasalVerb():
        return _PhrasalVerbDto.fromEntity(lexicalItem);
    }
  }
}
